/**
 * 后台类目管理路由
 */
const express = require('express');

// 用户中间件
const user = require('../../middleware/user');
// 导航类目中间件
const category = require('../../middleware/category');
// 后台类目管理路由
const categoryApp = express();
categoryApp.use(user.lastLoginTime);

categoryApp.get('/',[category.getList],(req,res)=>{
    // 用户，文章类目
    let {user,category} = req;
    res.render('admin/category/index',{user,category})
});

categoryApp.post('/add',category.add,(req,res)=>{
    if(req.insertId){
        res.json({code:1,msg:'添加成功'});
    }else{
        res.json({code:0,msg:'添加失败'});
    }
});
categoryApp.get('/del',category.del,(req,res)=>{
    if(req.affectedRows){
        res.json({code:1,msg:'删除成功'});
    }else{
        res.json({code:0,msg:'删除失败'});
    }
});
categoryApp.post('/setName',category.setName,(req,res)=>{
    if(req.affectedRows){
        res.json({code:1,msg:'修改类目名成功'});
    }else{
        res.json({code:0,msg:'修改类目名失败'});
    }
});
categoryApp.post('/setIndex',category.setIndex,(req,res)=>{
    if(req.affectedRows){
        res.json({code:1,msg:'修改排序成功'});
    }else{
        res.json({code:0,msg:'修改排序失败'});
    }
});

module.exports = categoryApp;
